import subprocess 
import re 

def get_disk_type ():
    cmd = 'lsblk -d -o name,rota | grep sda'
    res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    res = res.stdout.readlines ()[0].decode().split ()[1]
    if res == '1':
        d_type = 'HDD'
    else:
        d_type = 'SSD'
        
def  get_disk_list ():
    disk_list = []
    cmd = "lsscsi | grep '/dev/sd'"
    res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    lines = res.stdout.readlines ()
    for i in lines:
        i.decode().split()[-1]
        disk_list.append (i)
    
    
def get_disk_sn ():
    cmd = "smartctl -x /dev/sda"
    res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).
    
def get_io_info (io):
    res = subprocess.Popen('lspci -vvv -ns {} | grep Subsystem'.format (io), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    lines = res.stdout.read().decode ().strip().split (':')

    
def main ():
    io_list = [] 
    net = subprocess.Popen('lspci | grep -i eth', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    lines = res.stdout.readlines ()
    for i in lines:
        if i not in io_list:
            data = i.decode()
            r = '.*?\sEthernet controller:'
            r = re.compile(r,re.S)
            res = re.findall (r,data)
            io = res[0].replace (' Ethernet controller:','')
            io_list.append( io.spilt (':')[0])
            
            get_io_info (io)
    
def get_ram_all(cmd):
    res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    lines = res.stdout.read()
    lines = lines.decode().split(':')[1].strip()